<?php

namespace Home\Controller;

use Home\Service\UserService;
use Home\Common\FIdConst;
use Home\Service\DrillService;

/**
 * 习题库Controller
 *
 * @author 李静波
 *        
 */
class DrillController extends PSIBaseController {

	/**
	 * 习题标签 - 主页面
	 */
	public function drillTagIndex() {
		$us = new UserService();
		if ($us->hasPermission(FIdConst::DRILL_TAG)) {
			$this->initVar();
			
			$this->assign("title", "习题标签");
			
			$this->display();
		} else {
			$this->gotoLoginPage("/Home/Drill/drillTagIndex");
		}
	}

	/**
	 * 习题库管理 - 主页面
	 */
	public function drillRepoIndex() {
		$us = new UserService();
		if ($us->hasPermission(FIdConst::DRILL_REPO)) {
			$this->initVar();
			
			$this->assign("title", "习题库管理");
			
			$this->display();
		} else {
			$this->gotoLoginPage("/Home/Drill/drillRepoIndex");
		}
	}

	/**
	 * 标签列表
	 */
	public function tagList() {
		if (IS_POST) {
			$params = [
					"start" => I("post.start"),
					"limit" => I("post.limit")
			];
			
			$ds = new DrillService();
			$this->ajaxReturn($ds->tagList($params));
		}
	}

	/**
	 * 新增或编辑习题标签
	 */
	public function editDrillTag() {
		if (IS_POST) {
			$params = [
					"id" => I("post.id"),
					"name" => I("post.name"),
					"note" => I("post.note"),
					"showOrder" => I("post.showOrder")
			];
			
			$ds = new DrillService();
			$this->ajaxReturn($ds->editDrillTag($params));
		}
	}

	/**
	 * 获得某个习题标签的详细信息
	 */
	public function tagInfo() {
		if (IS_POST) {
			$params = [
					"id" => I("post.id")
			];
			
			$ds = new DrillService();
			$this->ajaxReturn($ds->tagInfo($params));
		}
	}

	/**
	 * 习题分类
	 */
	public function drillCategoryList() {
		if (IS_POST) {
			$ds = new DrillService();
			$this->ajaxReturn($ds->drillCategoryList());
		}
	}

	/**
	 * 习题列表
	 */
	public function drillList() {
		if (IS_POST) {
			$params = [
					"id" => I("post.id")
			];
			
			$ds = new DrillService();
			$this->ajaxReturn($ds->drillList($params));
		}
	}
}